package com.wyp168.serviceedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyp168.serviceedu.entity.EduTeacher;
import com.wyp168.serviceedu.mapper.EduTeacherMapper;
import com.wyp168.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author wyp168
 * @since 2022-04-26
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Override
    public Map<String, Object> getTeacherPage(Integer pageNo, Integer pageSize) {

        QueryWrapper<EduTeacher> wrapper= new QueryWrapper<>();
        wrapper.orderByDesc("id");

        Page<EduTeacher> pageParam = new Page<>(pageNo,pageSize);
        baseMapper.selectPage(pageParam,wrapper);

        List<EduTeacher> records = pageParam.getRecords();
        long total = pageParam.getTotal();
        boolean hasNext = pageParam.hasNext();
        boolean hasPrevious = pageParam.hasPrevious();

        //将查询到的数据封装到map集合中，并返回
        Map<String,Object> map = new HashMap<>();
        map.put("items",records);
        map.put("current",pageParam.getCurrent());
        map.put("pages",pageParam.getPages());
        map.put("total",total);
        map.put("size",pageParam.getSize());
        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);
        return map;

    }
}
